package com.ruoyi.zsyh.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.zsyh.domain.ZsyhAgentPartsattribute;
import com.ruoyi.zsyh.mapper.ZsyhAgentPartsMapper;
import com.ruoyi.zsyh.domain.ZsyhAgentParts;
import com.ruoyi.zsyh.service.IZsyhAgentPartsService;
import com.ruoyi.common.core.text.Convert;

/**
 * 大区商城配件管理Service业务层处理
 * 
 * @author yuexl
 * @date 2021-12-16
 */
@Service
public class ZsyhAgentPartsServiceImpl implements IZsyhAgentPartsService 
{
    @Autowired
    private ZsyhAgentPartsMapper zsyhAgentPartsMapper;

    /**
     * 查询大区商城配件管理
     * 
     * @param id 大区商城配件管理ID
     * @return 大区商城配件管理
     */
    @Override
    public ZsyhAgentParts selectZsyhAgentPartsById(String id)
    {
        return zsyhAgentPartsMapper.selectZsyhAgentPartsById(id);
    }

    /**
     * 查询大区商城配件管理列表
     * 
     * @param zsyhAgentParts 大区商城配件管理
     * @return 大区商城配件管理
     */
    @Override
    public List<ZsyhAgentParts> selectZsyhAgentPartsList(ZsyhAgentParts zsyhAgentParts)
    {
        return zsyhAgentPartsMapper.selectZsyhAgentPartsList(zsyhAgentParts);
    }

    /**
     * 新增大区商城配件管理
     * 
     * @param zsyhAgentParts 大区商城配件管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertZsyhAgentParts(ZsyhAgentParts zsyhAgentParts)
    {
        zsyhAgentParts.setCreateTime(DateUtils.getNowDate());
        int rows = zsyhAgentPartsMapper.insertZsyhAgentParts(zsyhAgentParts);
        insertZsyhAgentPartsattribute(zsyhAgentParts);
        return rows;
    }

    /**
     * 新增大区商城配件管理
     *
     * @param zsyhAgentParts 大区商城配件管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertZsyhAgentPartsApplet(ZsyhAgentParts zsyhAgentParts)
    {
        zsyhAgentParts.setCreateTime(DateUtils.getNowDate());
        return zsyhAgentPartsMapper.insertZsyhAgentParts(zsyhAgentParts);
    }

    /**
     * 修改大区商城配件管理
     * 
     * @param zsyhAgentParts 大区商城配件管理
     * @return 结果
     */
    @Transactional
    @Override
    public int updateZsyhAgentParts(ZsyhAgentParts zsyhAgentParts)
    {
        zsyhAgentParts.setUpdateTime(DateUtils.getNowDate());
        zsyhAgentPartsMapper.deleteZsyhAgentPartsattributeByPartsId(zsyhAgentParts.getId());
        insertZsyhAgentPartsattribute(zsyhAgentParts);
        return zsyhAgentPartsMapper.updateZsyhAgentParts(zsyhAgentParts);
    }

    public int updateZsyhAgentPartsApplet(ZsyhAgentParts zsyhAgentParts)
    {
        zsyhAgentParts.setUpdateTime(DateUtils.getNowDate());
        return zsyhAgentPartsMapper.updateZsyhAgentParts(zsyhAgentParts);
    }

    /**
     * 删除大区商城配件管理对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteZsyhAgentPartsByIds(String ids)
    {
        zsyhAgentPartsMapper.deleteZsyhAgentPartsattributeByPartsIds(Convert.toStrArray(ids));
        return zsyhAgentPartsMapper.deleteZsyhAgentPartsByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除大区商城配件管理信息
     * 
     * @param id 大区商城配件管理ID
     * @return 结果
     */
    @Override
    public int deleteZsyhAgentPartsById(String id)
    {
        zsyhAgentPartsMapper.deleteZsyhAgentPartsattributeByPartsId(id);
        return zsyhAgentPartsMapper.deleteZsyhAgentPartsById(id);
    }

    /**
     * 新增会长商城产品规格信息
     * 
     * @param zsyhAgentParts 大区商城配件管理对象
     */
    public void insertZsyhAgentPartsattribute(ZsyhAgentParts zsyhAgentParts)
    {
        List<ZsyhAgentPartsattribute> zsyhAgentPartsattributeList = zsyhAgentParts.getZsyhAgentPartsattributeList();
        String id = zsyhAgentParts.getId();
        if (StringUtils.isNotNull(zsyhAgentPartsattributeList))
        {
            List<ZsyhAgentPartsattribute> list = new ArrayList<ZsyhAgentPartsattribute>();
            for (ZsyhAgentPartsattribute zsyhAgentPartsattribute : zsyhAgentPartsattributeList)
            {
                zsyhAgentPartsattribute.setPartsId(id);
                list.add(zsyhAgentPartsattribute);
            }
            if (list.size() > 0)
            {
                zsyhAgentPartsMapper.batchZsyhAgentPartsattribute(list);
            }
        }
    }

    public ZsyhAgentParts getAgentPartsMaxSort(String agentId){
        return zsyhAgentPartsMapper.getAgentPartsMaxSort(agentId);
    }

    public Integer batchSaveZsyhAgentPartsattribute(List<ZsyhAgentPartsattribute> list, String partsId){
        zsyhAgentPartsMapper.deleteZsyhAgentPartsattributeByPartsId(partsId);
        return zsyhAgentPartsMapper.batchZsyhAgentPartsattribute(list);
    }

    public int updateIsShow(String isShow, String id){
        return zsyhAgentPartsMapper.updateIsShow(isShow, id);
    }
}
